﻿// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.

// 日期年月日格式
String.prototype.toDateString = function () {
    if (this == null || this.length == 0) return "";
    return new Date(this.replace(/-/g, "/")).Format("yyyy-MM-dd");
};

// 日期月日时分格式
String.prototype.toMonthMinuteString = function () {
    if (this == null || this.length == 0) return "";
    return new Date(this.replace(/-/g, "/")).Format("MM-dd hh:mm");
};

// 日期年月日时分格式
// value.toDateTimeString();
// value.toDateTimeString("yyyy-MM-dd hh:mm");
String.prototype.toDateTimeString = function (fmt) {
    //console.info(this);
    //return "";

    //var thisDate = new Date(parseInt(this.replace("/Date(", "").replace(")/", ""), 10));
    //var thisDate = new Date(this);
    //var year = thisDate.getFullYear();
    //var month = thisDate.getMonth() + 1;
    //var day = thisDate.getDate();
    //var hh = thisDate.getHours();
    //var mm = thisDate.getMinutes();
    //var ss = thisDate.getSeconds();
    //if (type == "yyyy-MM-dd HH:mm:ss") {
    //    return year + "-" + month + "-" + day + " " + hh + ":" + mm; //  + ":" + ss
    //} else {
    //    return year + "-" + month + "-" + day;
    //}
    //return thisDate.toCNString(type);

    if (this == null || this.length == 0) return "";
    //var that = new Date(this);

    //console.info(this);
    //console.info(that);
    if (fmt == undefined || fmt.length == 0) {
        fmt = "yyyy-MM-dd";
    }

    //console.info(Date(this));
    //console.info(fmt);
    //var date = this;
    //var date = this.replace(/-/g, "/");

    //var rst1 = new Date(date).Format(fmt);
    //console.info(rst1);

    //var rst2 = DateFormat(new Date(date), fmt);
    //console.info(rst2);
    //console.info(fmt);

    return new Date(this.replace(/-/g, "/")).Format(fmt);
};

// 日期时间格式处理
// that--日期
// fmt --输出格式
function DateFormat(that, fmt) {

    //console.info(typeof (that));

    var o = {
        "M+": that.getMonth() + 1, //月份   
        "d+": that.getDate(), //日   
        "h+": that.getHours(), //小时   
        "m+": that.getMinutes(), //分   
        "s+": that.getSeconds() //秒   
    };
    if (/(y+)/.test(fmt)) { //根据y的长度来截取年  
        fmt = fmt.replace(RegExp.$1, (that.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (o.hasOwnProperty(k)) {
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}

// 将时间转换为指定格式的字符串
// var time1 = new Date().Format("yyyy-MM-dd");
// new Date(1469281964000).Format("yyyy-MM-dd hh:mm:ss");  
// new Date("2018/6/8 20:56:55").Format("MM-dd hh:mm");

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份   
        "d+": this.getDate(), //日   
        "h+": this.getHours(), //小时   
        "m+": this.getMinutes(), //分   
        "s+": this.getSeconds() //秒   
    };
    if (/(y+)/.test(fmt)) { //根据y的长度来截取年  
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (o.hasOwnProperty(k)) {
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
};



// 提示内容格式化
function tipsFormatter(value, row, index) {
    return value == null ? "" : (value.length > 3 ? "<span data-toggle='tooltip' data-placement='top' title='" + value + "'>" + value + "</span>" : value);
}



// 获取内容区域高度，以供表格重新定义高度
function getHeight() {
    var heightCorrection = 75;
    return $(window).height() - $('.page-header').outerHeight(true) - heightCorrection;
}


/// <summary>
///     页面跳转
/// </summary>
function Redirect(url) {
    window.location.href = url;
}

function Page(url) {
    window.location.href = url;
}







